/** 
 *  @file
 *  @brief   槽（C）形（CHAN）梁截面属性使用解析公式计算类
 *  @author  yuanchenxi
 *  @date    2024.03.29
 *  @version v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#include "ChanSectionFormulaCalculator.h"
#include "DataStructure/Common/Real.h"

using SG::DataStructure::Common::Real;
using SG::DataStructure::FEM::PBARLData;
using SG::DataStructure::FEM::PBARData;
using SG::FEMSolver::Element::ChanSectionFormulaCalculator;

void ChanSectionFormulaCalculator::Compute
(
const SG::DataStructure::FEM::PBARLData& section,
_OUT SG::DataStructure::FEM::PBARData&   property,
_OUT SG::Algebra::Point&                 centroid
) const
{
    Real tw{section.m_dimension[2]};
    Real tf{section.m_dimension[3]};
    Real b{section.m_dimension[0] - 0.5 * tw};
    Real h{section.m_dimension[1] - tf};
    Real bf{section.m_dimension[0] - tw};
    Real hw{section.m_dimension[1] - 2.0 * tf};

    property.m_id  = section.m_id;
    property.m_mId = section.m_mId;
    property.m_A   = 2.0 * tf * bf + (h + tf) * tw;
    // Real yS = 0.0;
    // Real zS = -b * b * tf / (2.0 * b * tf + h * tw / 3.0);
    // Real yC = 0.0;
    Real zC = bf * tf * (bf + tw) / property.m_A;
    property.m_I1  = tw * (h + tf) * (h + tf) * (h + tf) / 12.0 + bf * tf * tf * tf / 6.0 + bf * tf * h * h * 0.5;
    property.m_I2  = (h + tf) * tw * tw * tw / 12.0 + tf * bf * bf * bf / 6.0 + tf * bf * (bf + tw) * (bf + tw) * 0.5 -
                     property.m_A * zC * zC;
    property.m_I12 = 0.0;
    property.m_J   = (2.0 * b * tf * tf * tf + h * tw * tw * tw) / 3.0;
    property.m_K1  = tw * hw / property.m_A;
    property.m_K2  = 2.0 * tf * bf / property.m_A;
    property.m_NSM = section.m_nsm;
    property.m_FE  = 0.0;
    property.SetStressPoints ({ 0.5 * (h + tf), -zC + b,
                               -0.5 * (h + tf), -zC + b,
                               -0.5 * (h + tf), -zC - 0.5 * tw,
                                0.5 * (h + tf), -zC - 0.5 * tw});
    centroid.m_x = 0.0;
    centroid.m_y = 0.0;
    centroid.m_z = 0.0;
}